const { no, ok } = require('../../utils/utlis');
const JWT = require('../../utils/jwt');
const articleService = require('../../services/client/articleService');
module.exports = {
	list: async (req, res, next) => {
		try {
			let token = JWT.decrypt(req.headers.token);
			let userId = token.id || 0;

			let { keywords, lable, type, pageNum, pageSize } = req.body;

			let data = await articleService.list(userId, keywords, lable, type, pageNum, pageSize);
			res.send(ok(data));
		} catch (error) {
			res.send(no(error.message));
		}
	},
	detail: async (req, res, next) => {
		try {
			let { id } = req.body;
			let obj = await articleService.detail(id);
			res.send(ok(obj));
		} catch (error) {
			res.send(no(error.message));
		}
	},
	listByTypeId: async (req, res, next) => {
		try {
			let token = JWT.decrypt(req.headers.token);
			let userId = token.id || 0;
			let { id, pageNum, pageSize } = req.body;
			let data = await articleService.listByTypeId(userId, id, pageNum, pageSize);
			res.send(ok(data));
		} catch (error) {
			res.send(no(error.message));
		}
	},
	giveLike: async (req, res, next) => {
		try {
			let { id: userId } = JWT.decrypt(req.headers.token);
			let { id: acticleId } = req.body;
			let obj = await articleService.giveLike(userId, acticleId);
			res.send(ok(obj));
		} catch (error) {
			res.send(no(error.message));
		}
	}
};
